import {GameModel, mainCtx} from "./core.ts";
import {TankImage} from "./const.ts";
import {GameMap} from "./GameMap.ts";

const stateMap = {
    0: [257, 128, 15, 15],
    1: [272, 128, 16, 16],
    2: [288, 128, 15, 15],
} as { [key: number]: number[] }

export class Bomb extends GameModel {
    state = 0
    _preTime = 0
    compactLevel = -1

    constructor(x: number, y: number) {
        super(x,y, 24,24,mainCtx);
    }

    render(): void {
        let x = stateMap[this.state]
        this.ctx.drawImage(TankImage, x[0], x[1], x[2], x[3], this.x -12, this.y -12, 24, 24)
    }

    update(time: number): void {
        let delta = time - this._preTime
        if (delta > 150) {
            if (this._preTime != 0) {
                this.state++
            }
            this._preTime = time
        }
        if (this.state > 2) {
            this.state = 0
            this.destroy()
        }
    }

    compact(_: GameModel | GameMap): void {
    }

}